# -*- coding: utf-8 -*-

import os
from flask import render_template

from . import upload
from gzone.forms import AnnouncementForm


@upload.route('/', methods=['GET', 'POST'])
def index():
    form = AnnouncementForm()

    if form.validate_on_submit():
        print form.title.data
        print form.content.data
        img = form.image.data
        if img is not None:
            file_path = os.path.join(
                upload.root_path,
                upload.static_folder,
                'images',
                img.filename
            )
            print img.filename
            img.save(file_path)

    return render_template('upload/index.html', form=form)
